from pages.LoginPage import LoginPage
from selenium.webdriver.common.by import By
from selenium import webdriver


class NewSourcePage(LoginPage):
    loc_newTask = (By.XPATH, '//*[contains(text(), "新资源")]')  # //*[@id="today$Menu"]/li[2]/a/text()
    # loc_newTask = (By.XPATH,'//*[@id="today$Menu"]/li[2]/a/text()')         #//*[@id="today$Menu"]/li[2]/a/text()

    loc_queryinfbutton = (By.XPATH, '//*[contains(text(), "查 询")]/..')

    loc_name = (By.XPATH, '//input[@placeholder="请输入姓名"]')
    loc_phone = (By.XPATH, '//input[@placeholder="请输入手机号"]')

    loc_allocateTime = (By.XPATH, '//span/input[@placeholder="开始日期"]')
    startTime = (By.XPATH, '//tr/td[@title="%s"]')
    endTime = (By.XPATH, '//tr/td[@title="%s"]')

    timebutton = ('lick text', '确 定')

    loc_degree = (By.XPATH, '//*[contains(text),"请选择学历"]')
    degreeOptions = '//*[contains(text(), "%s")]'

    loc_product = (By.XPATH, '//*[contains(text),"请选择产品线"]')
    productOptions = '//*[contains(text(), "%s")]'

    loc_HRname = (By.XPATH, '//*[contains(text),"请输入人事专员"]')

    loc_channel = (By.XPATH, '//*[contains(text),"请选择渠道"]')
    channelOptions = '//*[contains(text(), "%s")]'

    loc_source = (By.XPATH, '//*[contains(text),"请选择来源"]')
    sourceOptions = '//*[contains(text(), "%s")]'

    loc_sex = (By.XPATH, '//*[contains(text),"请输入性别"]')
    sexOptions = '//*[contains(text(), "%s")]'

    loc_age = (By.XPATH, '//*[contains(text),"Mini"]')
    ageOptions = '//*[contains(text(), "%s")]'

    loc_querybutton = (By.XPATH, '//*[contains(text),"查 询"]')
    loc_resetbutton = (By.XPATH, '//*[contains(text),"重 置"]')

    def __init__(self, browser):
        super().__init__(browser)
        self.login()
        self.find_ele(self.loc_currentTask).click()
        self.find_ele(self.loc_newTask).click()

    def __click_queryinfbutton(self):
        self.find_ele(self.loc_queryinfbutton).click()

    def __input_name(self, name):
        self.find_ele(self.loc_name).send_keys(name)

    def __input_phone(self, phone):
        self.find_ele(self.loc_phone).send_keys(phone)

    def __input_allocatetime(self, starttime, endtime):
        self.find_ele(self.loc_allocateTime).click()
        self.find_ele(self.startTime).send_keys(starttime)
        self.find_ele(self.endTime).send_keys(endtime)
        self.find_ele(self.timebutton).clck()

    def __choice_degree(self, degree):
        self.find_ele(self.loc_degree).click()
        degreeoptions = (By.XPATH, self.degreeOptions % degree)
        self.find_ele(degreeoptions).click()

    def __choice_product(self, product):
        self.find_ele(self.loc_product).click()
        productoptions = (By.XPATH, self.productOptions % product)
        self.find_ele(productoptions).click()

    def __input_hrname(self, hrname):
        self.find_ele(self.loc_HRname).send_keys(hrname)

    def __choice_channel(self, channel):
        self.find_ele(self.loc_channel).click()
        channeloptions = (By.XPATH, self.channelOptions % channel)
        self.find_ele(channeloptions).click()

    def __choice_source(self, source):
        self.find_ele(self.loc_source).click()
        sourceoptions = (By.XPATH, self.channelOptions % source)
        self.find_ele(sourceoptions).click()

    def __choice_sex(self, sex):
        self.find_ele(self.loc_sex).click()
        sexoptions = (By.XPATH, self.channelOptions % sex)
        self.find_ele(sexoptions).click()

    def __choice_age(self, age):
        self.find_ele(self.loc_age).click()
        ageoptions = (By.XPATH, self.ageOptions % age)
        self.find_ele(ageoptions).click()

    def __click_querybutton(self):
        self.find_ele(self.loc_querybutton).click()

    def __click_resetbutton(self):
        self.find_ele(self.loc_querybutton).click()

    def queryinf_positive(self, name, phone, starttime, endtime, degree, product, hrname,
                          channel, source, sex, age):  # 正向验证
        self.__click_queryinfbutton()
        self.__input_name(name)
        self.__input_phone(phone)
        self.__input_allocatetime(starttime, endtime)
        self.__choice_degree(degree)
        self.__choice_product(product)
        self.__input_hrname(hrname)
        self.__choice_channel(channel)
        self.__choice_source(source)
        self.__choice_sex(sex)
        self.__choice_age(age)
        self.__click_querybutton()

    # def queryInf_nullValue(self):
    #     self.find_ele(self.loc_queryInfButton).click()
    #     self.find_ele(self.loc_querybutton).click()


if __name__ == '__main__':
    a = NewSourcePage(webdriver.Firefox())
    a.queryinf_positive('name', 'phone', '2023年2月17日', '2023年9月17日', 'degree', 'product', 'hrname',
                        'channel', 'source', 'sex', 'age')
    b = input()
